<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
	<meta charset="UTF-8">
	<title>项目管理系统</title>
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" />
	<link rel="stylesheet" href="../css/qwe.css" />
</head>
<body class="body">
	<c:set var="name" value="willen" scope="session"/>
	<div class="navbar navbar-fixed-top">
		<div class="navbar-inner">
			<div class="container">
				<a class="brand" href="main.jspx">项目管理系统</a>
			</div>
		</div>
	</div>
	<div class="container">
	  <div class="row">
		<div class="span3">
			<div style="padding: 8px 0;" class="well">
				<ul class="nav nav-list">
				  <li class="nav-header"><h4 style="color:#005580">${sessionScope.project.name}</h4></li>
				  <li class="divider"></li>
				  <li class="active"><a href="#"><i class="icon-white icon-home"></i>最新动态</a></li>
				  <li><a href="goal.html"><i class="icon-flag"></i>目标</a></li>
				  <li><a href="document.html"><i class="icon-folder-open"></i>资料库</a></li>
				  <li><a href="file.html"><i class="icon-file"></i>文件共享</a></li>
				  <li><a href="contact.jspx"><i class="icon-user"></i>联系人</a></li>
				  <li><a href="idea.html"><i class="icon-fire"></i>想法</a></li>
				  <li><a href="#"><i class="icon-warning-sign"></i>Bug</a></li>
				  <li><a href="#"><i class="icon-cog"></i>项目设置</a></li>
				</ul>
			</div>
		</div>
		<div class="span6">
		  	<ul class="breadcrumb" style="margin-bottom:0px;border-radius: 3px 3px 0 0;">
				<li class="active">
					<i class="icon-th"></i>你在想什么？
				</li>
			</ul>
			<div class="wall">
					<textarea name="" id="areatext" style="width:415px" rows="3"></textarea>
					<button id="release" class="btn btn-primary">发布</button>
			</div>
			<ul class="breadcrumb" style="margin-bottom:0px;border-radius: 3px 3px 0 0;margin-top:20px">
				<li class="active">
					<i class="icon-th"></i>信息流${requestScope.eyName}
				</li>
			</ul>
			<!-- start 微博更新提示 -->
			<div class="alert" style="margin-top:5px;display:none;">
			  <button type="button" class="close" data-dismiss="alert">&times;</button>
			   <a href="project.jspx?projectId=${sessionScope.project.id }">有<strong id="al"></strong>条微博更新，请点击查看</a>
			</div>
			<!-- end -->
				<div class="wall" id="divComments">
				<c:forEach var="message" varStatus="status" items="${requestScope.list.list}">
				<blockquote>
					<i class="icon-user"></i><strong style="font-size:16px;">${message.employeeName}</strong>
					<p id="mood" style="font-size:14px;line-height:1.5;margin-top:10px;">${message.content}</p>
					<small>发表于${message.time }</small>
					<a href="#myModal" class="amessage" id="${message.id }" data-toggle="modal">评论</a><br/>
					<c:forEach var="comment" items="${requestScope.commentList}">
						<c:if test="${message.id==comment.messageId}">
							${comment.username}<small>${comment.comment}&nbsp;&nbsp;发表于${comment.time}</small><br/>
						</c:if>
					</c:forEach>
					<hr>
				</blockquote>
				</c:forEach>
				</div>
				<!-- start评论层 -->
			<!-- Modal -->
			<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			  <div class="modal-header">
			    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
			    <h4 id="myModalLabel">发表评论</h4>
			  </div>
			  <div class="modal-body">
			  	<h5 id="non" style="display:none;color:#C09853;">内容不能为空</h5>
			  	<form action="mcs.jspx" id="form1" method="post" enctype="application/x-www-form-urlencoded">
			  		<input type="hidden" name="projectId" value="${sessionScope.project.id }"/>
			  		<input type="hidden" name="messageId" id="pd"/>
			    	<input style="border-color:#FFB941;" type="text" name="comment" class="span6" id="textComment"/>
			    </form>
			  </div>
			  <div class="modal-footer">
			    <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
			    <button id="commentBtn" class="btn btn-primary">发表</button>
			  </div>
			</div>
			<!-- end Div -->
			  <div class="pagination pull-right">
			    <ul>
					<li><a href="project.jspx?projectId=${sessionScope.project.id }&p=1">&larr; Older</a></li>
					<c:forEach var="pageList" items="${requestScope.list.slider }" begin="0" end="4">
						<li><a href="project.jspx?projectId=${sessionScope.project.id}&p=${pageList}">${pageList}</a></li>
					</c:forEach>
					<li><a href="project.jspx?projectId=${sessionScope.project.id}&p=${requestScope.list.totalPages}">Newer →</a></li>	
			    </ul>
			  </div>
		</div>
		<div class="span3">
			<div class="box">
				<div class="head">${sessionScope.curr_employee.name}的任务</div>
				<ul>
					<li><a href="#">任务1</a></li>
					<li><a href=""></a>任务1</li>
					<li><a href=""></a>任务1</li>
				</ul>
			</div>
		</div>
	  </div>
	</div>
		<script src="../js/jquery.js" type="text/javascript"></script>
		<script type="text/javascript" src="../js/qwe.js"></script>
        <script type="text/javascript" src="../js/at.js"></script>
        <script type="text/javascript" src="../js/caret.js"></script>
 	<script type="text/javascript">
		var xmlHttp;
    	//创建Ajax引擎
    	function createXmlHttp() {
    		if(window.ActiveXObject) {
	    		//IE
    			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    	} else {
	    		//Chrome firefox 
	    		xmlHttp = new XMLHttpRequest();
	    	}
    	}
    	
    	function callback() {
    		var serverCode = xmlHttp.readyState;
    		if(serverCode == 4) {
    			var httpCode = xmlHttp.status;
    			if(httpCode == 200) {
    				//接受服务器返回的字符串
					var json=JSON.parse(xmlHttp.responseText);
    				if(json==null||json==""){
    					return;
    				}
					//动态更新消息块
    					var div=document.getElementById("divComments");
    					var block=document.createElement("blockquote");
    					var first=div.firstChild;
    					var i=document.createElement("i");
    					i.setAttribute("class","icon-user");
    					var strong=document.createElement("strong");
    					strong.setAttribute("style","font-size:16px;");
    					var name=document.createTextNode(json.employeeName);
    					strong.appendChild(name);
    					var p=document.createElement("p");
    					p.setAttribute("id","mood");
    					p.setAttribute("style","font-size:14px;line-height:1.5;margin-top:10px;");
    					var textarea=document.createTextNode(json.content);
    					var small=document.createElement("small");
    					var d =new Date(json.createTime);
    					var t1=d.getTime();
    					var d2=new Date();
    					var t2=d2.getTime();
    					var simbleTime=Math.floor((t2-t1)/(1000*60));
    					var hourTime=simbleTime/60;
    					if(simbleTime<=1){
    						var time=document.createTextNode("发表于刚刚");
    						small.appendChild(time);
    					}else if(simbleTime>1&&simbleTime<60){
    						var time=document.createTextNode("发表于"+simbleTime+"分钟前");
    						small.appendChild(time);
    					}else if(hourTime>1&&hourTime<24){
    						var time=document.createTextNode("发表于"+hourTime+"小时前");
    						small.appendChild(time);
    					}
    					var a=document.createElement("a");
    					a.setAttribute("class","amessage");
    					a.setAttribute("href","#myModal");
    					a.setAttribute("id",json.id);
    					a.setAttribute("data-toggle","modal");
    					var commentText=document.createTextNode("评论");
    					p.appendChild(textarea);
    					a.appendChild(commentText);
    					block.appendChild(i);
    					block.appendChild(strong);
    					block.appendChild(p);
    					block.appendChild(small);
    					block.appendChild(a);
    					var hr=document.createElement("hr");
    					block.appendChild(hr);
    					div.insertBefore(block,first);
    					$(".amessage").click(function(){
    		    			var mid=$(this).attr("id");
    		    			$("#pd").val(mid);
    		    		});
    			} else {
    				
    			}
    		}
    	};
    	document.getElementById("release").onclick =function(){
    		//1.创建Ajax引擎
    		createXmlHttp();
    		//2.告诉引擎请求的服务器地址(ajax.jspx)，请求方式(get)，是否异步请求(true)
    		var name = document.getElementById("areatext").value;
    		document.getElementById("areatext").value="";
    		//xmlHttp.open("get","ajax.jspx?name="+name+"&xxx="+new Date().getTime(),true);
    		xmlHttp.open("get","message.jspx?name="+encodeURIComponent(name),true);
    		//3.设置回调函数
    		xmlHttp.onreadystatechange = callback;
    		//4.请求服务器
    		xmlHttp.send();
    	};
    	function gopost(){
    		$.post("project.jspx",function(num){
    			$("#al").empty();
    			if(num!=0){
    				$("#al").append(num);
    				$(".alert").show();
    			}
        	});
    		setTimeout("gopost()",10000);
    	}
    	gopost();
    	$(function(){
    		$(".amessage").click(function(){
    			var mid=$(this).attr("id");
    			$("#pd").val(mid);
    		});
    		$("#commentBtn").click(function(){
    			var str=$("#textComment").val();
    			if(!str){
    				$("#non").show();
    				return;
    			}
    				$("#form1").submit();
    			
    		});
    		$("#textComment").focus(function(){
    			$("#non").hide();
    		});
    	});
  
 	</script>
</body>
</html>